#include<iostream>
using namespace std;
typedef long long LL;
const LL mod = 1e9 + 7;
const int N = 1e6 + 10;
LL s[N];
int q;
LL l, r;
int main()
{
	cin >> q;
	
	while (q--) {
		cin >> l >> r;
		cout << (s[r] - s[l - 1] + mod) % mod << endl;	
	}
	return 0;
}
